<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
    <todo>
        <todo-title slot="todo-title" v-bind:title="title"></todo-title>
        <todo-items slot="todo-items" v-for="(item,index) in items" v-bind:item="item"  @remove="removeItem(index)"></todo-items>
    </todo>

</div>
</body>
<script>
    Vue.component("todo", {
        template: '<div>\
                    <slot name="todo-title"></slot>\
                    <ul>\
                        <slot name="todo-items"></slot>\
                    </ul>\
                  </div>'
    })
    Vue.component("todo-title", {
        template: '<div>{{title}}</div>',
        props:['title']
    })
    Vue.component("todo-items", {
        template: '<li>{{item}}--{{index}}<button @click="remove">删除</button></li>',
        props: ['item','index'],
        methods:{
            remove:function (index) {
                this.$emit('remove',index)
            }
        }
    })
    var vm = new Vue({
        el: "#app",
        data:{
            title:"cai",
            items:['Java','Linux','前端']
        },
        methods:{
            removeItem:function (index) {
                console.log("删除了:"+this.items[index]);
                this.items.splice(index,1);
            }
        }
    })
</script>
</html>